package org.raphaello.core.jobs;

import org.raphaello.Prototype.Raphaello;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.Log;

public class ColoredRectangleDrawer extends Job {
	
	private static final String TAG = "ColoredRectangleDrawer";

	public ColoredRectangleDrawer(String id) {
		super(id);
		declareProperty("x", "Number", "0");
		declareProperty("y", "Number", "0");
		declareProperty("width", "Number", "0");
		declareProperty("height", "Number", "0");
		declareProperty("color", "Color");
	}
	
	@Override
	public void work() {
		// Draw the colored rectangle
		
		String color = getColor();
		int x = getX();
		int y = getY();
		int width = getWidth();
		int height = getHeight();
		
		Log.d(TAG, "ColoredRectangle x=" + x + " y=" + y + " w=" + width + " h=" + height + " color=" + color);
		
		
		int c = 0;
		
		if(color.equals("red")){
			c = 0xFFFF0000;
		}
		else if(color.equals("blue")){
			c = 0xFF0000FF;
		}
		else if(color.equals("green")){
			c = 0xFF00FF00;
		}
		else if(color.equals("white")){
			c = 0xFFFFFFFF;
		}
		
		
		Paint paint = new Paint();
		paint.setColor(c);
		
		
		Canvas canvas = Raphaello.getView().getOffScreenCanvas();
		canvas.drawRect(x, y, x + width, y + height, paint);
	
	}

	
	/* Helper methods for properties */
	
	public final Integer getX() {
		return (Integer)getProperty("x");
	}
	
	public final Integer getY() {
		return (Integer)getProperty("y");
	}
	
	public final Integer getWidth() {
		return (Integer)getProperty("width");
	}
	
	public final Integer getHeight() {
		return (Integer)getProperty("height");
	}
	
	public final Integer getOpacity() {
		return (Integer)getProperty("opacity");
	}
	
	public final String getColor() {
		return (String)getProperty("color");
	}
}
